package com.demo.controller;


import com.demo.entity.AjaxResult;
import com.demo.entity.OrderEntity;
import com.demo.service.OrderService;
import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects;

@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {
    @Resource
    private  OrderService orderService;

    /**
     * 下单
     * @param tbOrder
     * @return
     */
    @PostMapping("/saveOrder")
    public AjaxResult saveOrder(@RequestBody OrderEntity tbOrder) {
        Preconditions.checkArgument(Objects.nonNull(tbOrder.getGoodsId()), "下单的商品ID不能为空");
        Preconditions.checkArgument(tbOrder.getOrderNum() > 0, "下单的商品数量必须大于0");
        return orderService.saveOrder(tbOrder);
    }

    /**
     * 测试list
     * @return
     */
    @GetMapping("/queryList")
    public AjaxResult queryList(){
        return orderService.queryList();
    }

}
